﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;

namespace WebSiteAdminTool.UI.Utils
{
    public static class Extensions
    {
        public static string[] GetNames<T>()// where T : Enum
        {
            List<string> enumNames = new List<string>();

            foreach (FieldInfo fi in typeof(T).GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                enumNames.Add(fi.Name);
            }

            return enumNames.ToArray();
        }

        public static IEnumerable<T> GetValues<T>()// where T : Enum
        {
            List<T> enumValues = new List<T>();

            Type t = typeof(T);
            foreach (FieldInfo fi in t.GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                enumValues.Add((T)Enum.Parse(t, fi.Name, false));
            }

            return enumValues.ToArray();
        }

        public static bool IsServiceCallSuccessfull(this AsyncCompletedEventArgs e)
        {
            return !e.Cancelled && null == e.Error;
        }
    }
}
